package com.bjsxt.common.interceptor;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.bjsxt.users.pojo.AAdmins;
import com.bjsxt.users.service.IUsersService;

/**
 * 管理员的验证登陆拦截器
 * @author wangshSxt
 *
 */
@Component("adminsAuthInterceptor")
public class AdminsAuthInterceptor extends HandlerInterceptorAdapter
{
	@Resource
	private IUsersService usersService;
	
	/**
	 * 执行之前拦截
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception
	{
		/*
		 * 从session中获取admins对象
		 * 判断是否为空
		 * */
		HttpSession session = request.getSession();
		AAdmins admins = (AAdmins) session.getAttribute("admins");
		if(admins != null)
		{
			/* 已经登陆 */
			return true ; 
		}
		
		/* 非法访问 */
		String info = "请先登陆" ;
		session.setAttribute("info", info);
		response.sendRedirect(request.getContextPath() + "/adminsLogin.htm");
		return false;
	}
}
